package com.xuetang9.t9.hotel.services.impl;
import com.xuetang9.t9.hotel.beans.MaintainRoom;
import com.xuetang9.t9.hotel.mapper.IMaintainRoomMapper;
import com.xuetang9.t9.hotel.mapper.condition.impl.MaintainRoomCondition;
import com.xuetang9.t9.hotel.services.IMaintainRoomService;
import com.xuetang9.t9.hotel.utils.HttpCodeEnum;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("MaintainRoomServiceImpl")
public class MaintainRoomServiceImpl implements IMaintainRoomService {


    @Autowired
    private IMaintainRoomMapper maintainRoomMapper;


    @Override
    public boolean save(MaintainRoom maintainRoom) {
        return maintainRoomMapper.insert(maintainRoom) > 0;
    }

    @Override
    public boolean remove(Integer id) {
        return maintainRoomMapper.delete(id) > 0;
    }

    @Override
    public boolean alter(MaintainRoom maintainRoom) {
        return maintainRoomMapper.update(maintainRoom) > 0;
    }

    @Override
    public PageBean findByAll(MaintainRoomCondition condition) {
        if(condition == null){
            condition = new MaintainRoomCondition();
        }
        List<MaintainRoom> maintainRooms = maintainRoomMapper.selectByAll(condition);
        PageBean pageBean = new PageBean();
        if(maintainRooms == null || maintainRooms.size() <= 0){
            pageBean.ok(HttpCodeEnum.DATA_NOT_NULL.getCode(),HttpCodeEnum.DATA_NOT_NULL.getErrorMessage());
        }else{
            pageBean.ok(maintainRooms);
            pageBean.setCount(findByCount(condition));
        }
        return pageBean;
    }

    @Override
    public Long findByCount(MaintainRoomCondition maintainRoomCondition) {
        return maintainRoomMapper.selectByCount(maintainRoomCondition);
    }

    @Override
    public Integer pageCount(Integer pageSize, MaintainRoomCondition maintainRoomCondition) {
        return null;
    }


}
